package ui.fragment.minefragment;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.LinearLayout;

import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.Observer;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.robot.RobotService;
import com.netease.nimlib.sdk.robot.RobotServiceObserve;
import com.netease.nimlib.sdk.robot.model.NimRobotInfo;
import com.netease.nimlib.sdk.robot.model.RobotChangedNotify;
import com.netease.nimlib.sdk.robot.model.RobotMsgType;
import com.qiyukf.unicorn.api.ConsultSource;
import com.qiyukf.unicorn.api.Unicorn;
import com.qiyukf.unicorn.ui.fragment.ServiceMessageFragment;

import java.util.List;

import base.BaseBean;
import base.fragment.BaseNetFragment;
import student.andlei.com.student.R;

/**
 * 在线客服
 */
public class OnlineServerFragment extends BaseNetFragment {

    public static Fragment getInstance() {

        return new OnlineServerFragment();
    }

    @Override
    public void success(String action, BaseBean baseBean) {

    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_onlineserver;
    }

    @Override
    protected void findViews() {

    }

    @Override
    protected void formatViews() {
        NIMClient.getService(RobotServiceObserve.class).observeRobotChangedNotify(robotChangedNotifyObserver, true);
    }

    private void GetBotInfo() {
        List<NimRobotInfo> robots = NIMClient.getService(RobotService.class).getAllRobots();

    }
    /**
     *   向机器人提问
     */
    private void TiwenRobotMessage() {
        // 该帐号为示例，请先注册
        String account = "testAccount";
        // 以单聊类型为例
        SessionTypeEnum sessionType = SessionTypeEnum.P2P;
        // 机器人帐号
        String robotAccount = "robotAccount";
        // 消息文案
        String text = "这是消息文案";
        // 机器人消息类型, 文本消息类型
        String type = RobotMsgType.TEXT;
        // 消息内容
        String content = "这是消息内容";
        // 创建机器人消息
        IMMessage message = MessageBuilder.createRobotMessage(account, sessionType, robotAccount, text, type, content, null, null);
        // 发送给对方
        NIMClient.getService(MsgService.class).sendMessage(message, false);
    }

    private Observer<RobotChangedNotify> robotChangedNotifyObserver = new Observer<RobotChangedNotify>() {
        @Override
        public void onEvent(RobotChangedNotify robotChangedNotify) {
            // 更新本地机器人信息缓存
        }
    };

    @Override
    protected void formatData() {

    }

    @Override
    protected void getBundle() {

    }

    @Override
    public void onClick(View view) {

    }
}
